package com.anhry.app.safety.servlet;


import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.anhry.app.safety.manage.system.service.SystemService;
import com.anhry.app.safety.util.Loggers;
import com.anhry.app.safety.util.Util;

/**
 * @date:2012-5-18
 * @remark:
 * @author:dongbin
 */
public class InitServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	
	public void init() throws ServletException {
		ServletContext sc = getServletContext();
		WebApplicationContext   ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext()); 
		SystemService systemService=(SystemService)ctx.getBean("systemServiceImpl");  

		try {
			Loggers.info("*----------------------------*");
			sc.setAttribute("CREATE", Integer.valueOf(0));//增加权限
			sc.setAttribute("READ", Integer.valueOf(1));//读取权限，一般选中菜单既有该权限
			sc.setAttribute("UPDATE", Integer.valueOf(2));//修改权限
			sc.setAttribute("DELETE", Integer.valueOf(3));//删除权限
			sc.setAttribute(Util.ALL_DEPT_LIST, systemService.getAllDeptList());//部门列表
			Loggers.info("部门信息数据初始化成功！");
			
			sc.setAttribute(Util.USER_GRADE_LIST, systemService.getUserGradeList());//用户级别
			Loggers.info("用户级别数据初始化成功！");
			
			sc.setAttribute(Util.SD_DEPT_LIST, systemService.getDeptList("3", Util.DEPT_CODE));//属地部门信息
			Loggers.info("属地部门数据初始化成功！");
			
			sc.setAttribute(Util.QU_DEPT_LIST, systemService.getQuDeptList());//县(市、区)、开发区部门列表
			Loggers.info("县(市、区)、开发区属地部门数据初始化成功！");
			
			sc.setAttribute(Util.ALL_CORP_TYPE, systemService.getCorpTypeList());
			Loggers.info("企业类型数据初始化成功！");
			
			sc.setAttribute(Util.MAX_CORP_TYPE, systemService.getMaxTypeList());
			Loggers.info("企业类型大类数据初始化成功！");
			
			sc.setAttribute(Util.HY_DEPT_LIST, systemService.getDeptMainList());
			Loggers.info("行业主管部门数据初始化成功！");
			
			Loggers.info("*----------------------------*");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {			
		PrintWriter out = response.getWriter();
		ServletContext sc = getServletContext();
		WebApplicationContext   ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext()); 
		SystemService systemService=(SystemService)ctx.getBean("systemServiceImpl");  
		try {
			Loggers.info("*----------------------------*");
			Loggers.info("*----------------------------*");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
		doGet(request,response);
	}
	
}
